<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>

    <FilterTable
      ref="businessMangerTable"
      columnsRef="repair_repairReception_repairBusinessManager_main"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isExportExcel2="true"
      exportFileName="电池预约单.xlsx"
      :isSelectColumn="false"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="columns => (this.selectColumns = columns)"
    >
    </FilterTable>

    <BaseDialog
      :visible.sync="issearch"
      :title="'经销商查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { getBookingData } from '@/api/serviceass/batteryService/booking';
import ownerSeacher from '../../../partsmanage/claim/approve/ownerSeacher';
import { dictionary } from '@/utils/dictMixin';
export default {
  name: 'servicessbatteryservicebookingindex',
  mixins: [dictionary],
  components: {
    ownerSeacher
  },
  data() {
    return {
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchParams: { xhrAbort: true },
      fetchApi: getBookingData,
      issearch: false
    }
  },
  methods: {
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin'
        },
        {
          type: 'INPUT',
          label: '预约单号',
          fieldName: 'bookingOrderNo'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license'
        },
        {
          type: 'INPUT',
          label: '工单号',
          fieldName: 'roNo'
        },
        {
          type: 'SELECT',
          label: '电池品牌:',
          fieldName: 'cellBrand',
          placeholder: '请选择...',
          itemList: this.createDictList('5014')
        },
        {type: 'RANGE_DATE', label: '开单日期', fieldName: 'createdAt1|createdAt2', valueFormat: 'yyyy-MM-dd', placeholder: '请选择'},
        {
          type: 'INPUT',
          label: '经销商名称',
          fieldName: 'dealerCode',
          placeholder: '请选择',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
              </div>
            );
          },
          change:p=>{
            if(!p){
              this.dealerCode=''
            }
          }
        },
      ]
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工单开单时间',
          dataIndex: 'createdAt',
          sorter: true,
          dateFormat: 'YYYY-MM-DD HH:mm:ss',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '工单号',
          dataIndex: 'roNo',
          sorter: true,
          width: 130
        },
        {
          title: '预约单号',
          dataIndex: 'bookingOrderNo',
          sorter: true,
          width: 130
        },
        {
          title: '经销商',
          dataIndex: 'ownerCode2',
          sorter: true,
          width: 160
        },
        {
          title: '电池品牌',
          dataIndex: 'cellBrand',
          sorter: true,
          dictItems: this.createDictList('5014')
        },
        {
          title: '店端电池维修负责人',
          dataIndex: 'cellRepairName',
          sorter: true,
        },
        {
          title: '店端负责人电话',
          dataIndex: 'cellRepairPhone',
          sorter: true,
        },
        {
          title: '服务顾问',
          dataIndex: 'serviceAdvisor',
          sorter: true,
        },
        {
          title: '车牌号',
          dataIndex: 'license',
          sorter: true,
          width: 160
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          sorter: true,
          width: 160
        },
        {
          title: '车型',
          dataIndex: 'model_name',
          sorter: true,
        },
        {
          title: '车辆销售日期',
          dataIndex: 'salesDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'YYYY-MM-DD',
          exportFormat: {
            t: 'd'
          }
        },
        {
          title: '公里数',
          dataIndex: 'inMileage',
          sorter: true,
          filter: true,
          filterType: 'number'
        },
        {
          title: '预约单状态',
          dataIndex: 'bookingOrderStatus',
          sorter: true,
          dictItems: this.createDictList('5007')
        },
        {
          title: '客户描述',
          dataIndex: 'customerDesc',
          sorter: true,
          width: 160
        },
      ];
    },
    changeHandle(val) {
      val.createdAt2 && (val.createdAt2 = val.createdAt2.split(' ')[0] + ' 23:59:59');
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    seacherFun(){
      this.issearch=true;
    },
    dealercloseHandler(val){
      console.info(val)
      if(val){
        this.topFilterList.find(x=>x.fieldName=='dealerCode').initialValue=val.dealerCode;
        this.fetchParams=Object.assign({
          dealerCode: val.dealerCode
        },this.fetchParams)
        this.dealerCode=val.dealerCode
      }
      this.issearch=false;
    }
  }
}
</script>
